 
  
    layui.use(['icheck','element',"laytpl",'laypage','form','laydate'], function() {
        var $ = layui.jquery,
        layer = layui.layer,
        laytpl = layui.laytpl,
        laypage = layui.laypage;
        var form = layui.form();
        var tjstate =0;
      
       
        
     
	    form.render(); 
	    
	    var pageNo = $("#pageNo").val();
    	var totalPage = $("#totalPage").val();
    	
    	
     $(".icon-im_dianhua1").on("click",function(){
        	
        	if(callcenterstate==0){
        		layer.msg('请开通轻客呼叫中心' );
        		return false;
			}
        	var tel =$(this).attr("data");
        	var cusid =$(this).attr("dataid"); 
        	
        	layer.confirm('请确认电话：'+tel, {
        		  btn: ['确认拨打'] //可以无限个按钮
        	      ,shade: 0
        		  ,btn1: function(index, layero){
        			 
        		   layer.msg('正在拨号，请勿关闭界面', {icon: 16},function(){
        			   layer.confirm('通话中：'+tel, {
        				   anim:2,
        				   offset: 't',
        	        		  btn: [ '挂断'] //可以无限个按钮
        	        	      ,shade: 0
        	        		  ,btn1: function(index, layero){
        	        			  layer.msg('正在挂断电话...', {icon: 16},function(){});
        	        			  $.ajax({
        	               			type : "get",
        	               			url : "http://127.0.0.1:3366/callhang?callback=cb_callout",
        	               			async:false,
        	               			dataType : "html",
        	               			success : function(data){
        	               				result = data;
        	               				//eval(result);  
        	               			}
        	               		}); 
        	        				 
        	        		  }
        			   }); 
        		   });
        			var telurl ="http://127.0.0.1:3366/callout?phone="+tel+"&callback=cb_callout&recordId="+cusid+"-"+currentuserid;
     				$.ajax({
             			type : "get",
             			url : telurl,
             			async:false,
             			dataType : "html",
             			success : function(data){
             				result = data;
             				//eval(result); 
             			}
             		}); 
    		        return false;
        		  } 
        		}  );
        	 
        })
        
    	
    	
    	//分页按钮
    	laypage({
            cont: 'page',
            curr: pageNo//'${pager.pageNo}'
            ,pages: totalPage//'${pager.totalPages}' //总页数
            ,
            groups: 5 //连续显示分页数
            ,
            skip: true,
            jump: function(obj, first) {
                //得到了当前页，用于向服务端请求对应数据
                var curr = obj.curr;
                if(!first) {
                	$("#skipToPage").val(curr);
                	$("#customerlistform").submit();
                }
            }
        }); 
    	
    	 getZsUser = function (o){
    		 var result ="";
    		  var values = o;
    			$.ajax({
        			type : "post",
        			url : "/customer/userlist",
        			data : values,
        			async:false,
        			dataType : "json",
        			success : function(data){
        				result = data;
        				//layer.msg('资源获取到线索库成功', {icon: 1},function(){
       					// window.location.href=url;
    					// });
        			}
        		});
    	  	 return result
    	 }
    	 
    	  
     
    	$(".searchbtnclean").on("click",function(){
    		$("#keyWord").val("");
    		$("#province").val("");
    		$("#address").val("");
    		$("#city").html("<option value=\"\">请选择市</option>");
		    $("#city").val("");
		    $("#category").val("");
		    $("#zizhiType").val("");
    	});
    	 
 
        //点击搜索
    	$(".customersearchbtn").on("click",function(){
    		var ky = $.trim($("#keyWord").val());
       	    $("#keyWord").val(ky);
       	    $("#skipToPage").val(1);
    		$(".customersearcheform").submit();
    	});
    	
    	 
    	
    	
   	   //设置跟进人
    	$(".gjjlbtn").on("click",function(){
    		   var cname = $(this).attr("dname");
    		   var cusid =  $(this).attr("data");
    		   var conid =  $(this).attr("cdata");
    		   var owner = $(this).attr("owner");
    			parent.layer.open({
    	  			  type: 2, 
    	  			  title:cname+'的资质跟进记录',
    	  			  area: ['95%', '95%'],
    	  			  content: "/customer/qualificationitemlist?cusid="+cusid+"&contractid="+conid+"&owner="+owner
    	  		 }); 
    	});
    	
    	
 	   //设置跟进人
    	$(".zzrybtn").on("click",function(){
    		   var cname = $(this).attr("dname");
    		   var cusid =  $(this).attr("data");
    		   var conid =  $(this).attr("cdata");
    		   var owner = $(this).attr("owner");
    			parent.layer.open({
    	  			  type: 2, 
    	  			  title:cname+'的资质人员',
    	  			  area: ['95%', '95%'],
    	  			  content: "/customer/qualificationuserlist?id="+cusid+"&contractid="+conid+"&owner="+owner
    	  		 }); 
    	});
    	
    	   //设置跟进人
    	$(".htbtn").on("click",function(){
    		   var cname = $(this).attr("dname");
    		   var cusid =  $(this).attr("data");
    		   var conid =  $(this).attr("cdata");
    			parent.layer.open({
    	  			  type: 2, 
    	  			  title:cname+'的合同详情',
    	  			  area: ['95%', '95%'],
    	  			  content: "/customer/contractinfo?id="+conid
    	  		 }); 
    	});
    	
    	
    	
    	   //设置跟进人
    	$(".gjbtn").on("click",function(){
    		   var cname = $(this).attr("dname");
    		   var cusid =  $(this).attr("data");
    		   var conid =  $(this).attr("cdata");
		       	 layer.open({
		             type:1,
		             content:$('.addlgjr'),
		             btn:['确定','取消'],
		             btnAlign:'c',
		             shadeClose:false,
		             title:cname+'的资质跟进人',
		             area:['600px','450px'],
		             maxWidth:800,
		             yes: function(layero, index){
		             	    var uid  = $("#uid").val();
		                 	$.ajax({
		                 		type : "post",
		                 		url : "/customer/savequalificationuser",
		                 		data : {cusid:cusid,uid:uid,contractid:conid},
		                 		dataType : "json",
		                 		success : function(data){
		                 			if (data == 1) {
		                 				layer.closeAll();
		                 				layer.msg("设置跟进人成功",{icon: 1},function(){
		                 					window.location.reload();
		                 				});
		                 			} else { 
		                 				layer.msg("设置跟进人失败",{icon: 2});
		                 			}
		                 		}
		                 	});
		             }
		        });
    	});
    	

    	
    
    });
	
 
 
